package com.cuitrip.business.tripservice.model;


import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.cuitrip.business.tripservice.TripEditActivity;
import com.cuitrip.component.Label;
import com.lab.adapter.IAdapterData;
import com.lab.utils.ArrayUtil;
import com.lab.utils.Constants;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ServiceInfo implements Serializable, ServiceListInterface, IAdapterData {

    public static final String KEY = "service_info";
    public static final int STATUS_UN_SYNC = -1;
    public static final int STATUS_CHECKING = 0;
    public static final int STATUS_CHECHED = 1;
    public static final int STATUS_CHECK_FAILED = 2;
    public static final int STATUS_DRAFT = 3;
    /**
     * 一口价
     */
    public static final String PAYWAY_ALL = "0";
    /**
     * 按人数计费
     */
    public static final String PAYWAY_PER = "1";
    /**
     * 免费
     */
    public static final String PAYWAY_FREE = "2";
    /**
     * 草稿状态
     */
    public static final int DRAFT_STATE = 2;
    /**
     * 在线提交状态
     */
    public static final int ONLINE_STATE = 1;
    private static final long serialVersionUID = -3984338984164873535L;
    @JSONField(name = "otherNotes")
    public OtherNotes otherNotes;
    public List<CategoryInfo> cateList;
    private  String timeZone;
    private String sid; //": 0,
    private String name; //": "阿亮带你看妈祖绕境",
    private String status; //": 0,
    private int checkStatus = -1; //": 0,
    private String type; //": 0,
    private String address; //": "彰化县",
    private String lat = "0"; //": null,
    private String lng = "0"; //": null,
    private String proc; //": null,
    private String city; //": null,
    private String cityAbbr = "";
    private String insiderId; //": 1,
    private String score; //": 0,
    private String serviceDescript; //": "阿亮带你看妈祖绕境",
    //    private List<String> pic; //": "[\"http://alicdn.aliyun.com/pic2.jpg\",\"http://alicdn.aliyun.com/pic2.jpg\"]",
    private String backPic; //": null,
    private String tag; //": null,
    private String moneyType; //": null,
    private String price = ""; //": 300,
    private String priceDesc; //": null,
    private int maxbuyerNum; //": 5,
    private int minBuyerNum;
    private String serviceTime; //": "3h",
    private String bestTime; //": "9:00~11:00",
    private String availableDate; //": 0,
    private String meetingWay; //": 2,
    private String extInfo; //": null,
    private String isDeleted; //": 0,
    private String gmtCreated; //": null,
    private String gmtModified; //": null,
    private String country; //": null
    private String priceType = "";
    private String descptWithNoPic;

    public void setDescptWithNoPic(String descptWithNoPic) {
        this.descptWithNoPic = descptWithNoPic;
    }

    private String meetingPlace;
    private String feeInclude;
    private String feeExclude;
    private String showCurrency;
    private String showPrice;
    @JSONField(name = "brightSpot")
    private String highLight;
    private String likeNum;
    private List<Label> labelList;
    private int preOrderDays;
    private int onlineState;

    private String serviceStory;

    private TripEditActivity.ContentMode editMode;
    @JSONField(name = "picDescript")
    private ArrayList<PictureDescription> pictureDescriptionList = new ArrayList<>();


    public ServiceInfo() {
        super();
        otherNotes = new OtherNotes();
    }

    public String getServiceStory() {
        return serviceStory;
    }

    public void setServiceStory(String serviceStory) {
        this.serviceStory = serviceStory;
    }

    public boolean isChecking() {
        return STATUS_CHECKING == checkStatus;
    }

    public boolean isChecked() {
        return STATUS_CHECHED == checkStatus;
    }

    public boolean isCheckFailed() {
        return STATUS_CHECK_FAILED == checkStatus;
    }

    public boolean isDraft() {
        return STATUS_DRAFT == checkStatus;
    }

    public boolean isUnSync() {
        return STATUS_UN_SYNC == checkStatus;
    }

    public String getShowCurrency() {
        return showCurrency;
    }

    public void setShowCurrency(String showCurrency) {
        this.showCurrency = showCurrency;
    }

    public String getShowPrice() {
        return showPrice;
    }

    public void setShowPrice(String showPrice) {
        this.showPrice = showPrice;
    }

    // tag &&tags??


    public String getMeetingPlace() {
        return meetingPlace;
    }

    public void setMeetingPlace(String meetingPlace) {
        this.meetingPlace = meetingPlace;
    }

    public String getFeeInclude() {
        return feeInclude;
    }

    public void setFeeInclude(String feeInclude) {
        this.feeInclude = feeInclude;
    }

    public String getFeeExclude() {
        return feeExclude;
    }

    public void setFeeExclude(String feeExclude) {
        this.feeExclude = feeExclude;
    }

    public String getPriceType() {
        return priceType;
    }

    public void setPriceType(String priceType) {
        this.priceType = priceType;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getCheckStatus() {
        return checkStatus;
    }

    public void setCheckStatus(int checkStatus) {
        this.checkStatus = checkStatus;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat;
    }

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng;
    }

    public String getProc() {
        return proc;
    }

    public void setProc(String proc) {
        this.proc = proc;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getInsiderId() {
        return insiderId;
    }

    public void setInsiderId(String insiderId) {
        this.insiderId = insiderId;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public String getServiceDescript() {
        return serviceDescript;
    }

    public void setServiceDescript(String serviceDescript) {
        this.serviceDescript = serviceDescript;
        try {
            if (serviceDescript != null) {
                StringBuilder sb = new StringBuilder();
                Pattern pattern = Pattern.compile(Constants.IMAGE_PATTERN);
                Matcher matcher = pattern.matcher(serviceDescript);
                int index = 0;
                while (matcher.find()) {
                    int start = matcher.start();
                    String temp = serviceDescript.substring(index, start);
                    index = matcher.end();
                    sb.append(temp);
                }
                if (index < serviceDescript.length() - 1) {
                    sb.append(serviceDescript.substring(index, serviceDescript.length()));
                }
                descptWithNoPic = sb.toString();
            }
        } catch (Exception e) {
            descptWithNoPic = serviceDescript;
        }
    }

    public String getDescptWithnoPic() {
        return descptWithNoPic;
    }

    public String getBackPic() {
        return backPic;
    }

    public void setBackPic(String backPic) {
        this.backPic = backPic;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getMoneyType() {
        return moneyType;
    }

    public void setMoneyType(String moneyType) {
        this.moneyType = moneyType;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getPriceDesc() {
        return priceDesc;
    }

    public void setPriceDesc(String priceDesc) {
        this.priceDesc = priceDesc;
    }

    public Integer getMaxbuyerNum() {
        return maxbuyerNum;
    }

    public void setMaxbuyerNum(int maxbuyerNum) {
        this.maxbuyerNum = maxbuyerNum;
    }

    public String getServiceTime() {
        return serviceTime;
    }

    public void setServiceTime(String serviceTime) {
        this.serviceTime = serviceTime;
    }

    public String getBestTime() {
        return bestTime;
    }

    public void setBestTime(String bestTime) {
        this.bestTime = bestTime;
    }

    public String getAvailableDate() {
        return availableDate;
    }

    public void setAvailableDate(String availableDate) {
        this.availableDate = availableDate;
    }

    public String getMeetingWay() {
        return meetingWay;
    }

    public void setMeetingWay(String meetingWay) {
        this.meetingWay = meetingWay;
    }

    public String getExtInfo() {
        return extInfo;
    }

    public void setExtInfo(String extInfo) {
        this.extInfo = extInfo;
    }

    public ExtInfo getExtInfoObject() {
        if (extInfo == null) {
            return null;
        }
        try {
            return JSON.parseObject(extInfo, ExtInfo.class);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public String getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(String isDeleted) {
        this.isDeleted = isDeleted;
    }

    public String getGmtCreated() {
        return gmtCreated;
    }

    public void setGmtCreated(String gmtCreated) {
        this.gmtCreated = gmtCreated;
    }

    public String getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(String gmtModified) {
        this.gmtModified = gmtModified;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getHighLight() {
        return highLight;
    }

    public void setHighLight(String highLight) {
        this.highLight = highLight;
    }

    public int getMinBuyerNum() {
        return minBuyerNum;
    }

    public void setMinBuyerNum(int minBuyerNum) {
        this.minBuyerNum = minBuyerNum;
    }

    public int getPreOrderDays() {
        return preOrderDays;
    }

    public void setPreOrderDays(int preOrderDays) {
        this.preOrderDays = preOrderDays;
    }

    public int getOnlineState() {
        return onlineState;
    }

    public void setOnlineState(int onlineState) {
        this.onlineState = onlineState;
    }

    public boolean isOtherInstructionEmpty() {
        if (otherNotes == null) {
            return true;
        }
        return TextUtils.isEmpty(otherNotes.getServiceNotice())
                && TextUtils.isEmpty(otherNotes.getServiceSafeTips())
                && TextUtils.isEmpty(otherNotes.getServiceWearTips())
                && TextUtils.isEmpty(otherNotes.getUnexpectedWeather());
    }

    public boolean isEmpty() {
        return serviceDescript == null || serviceDescript.length() == 0;
    }

    public boolean isTypeFree() {
        return priceType != null && PAYWAY_FREE.equals(priceType);
    }

    public String getCityAbbr() {
        return cityAbbr;
    }

    public void setCityAbbr(String cityAbbr) {
        this.cityAbbr = cityAbbr;
    }

    public OtherNotes getOtherNotes() {
        return otherNotes;
    }

    public void setOtherNotes(OtherNotes otherNotes) {
        this.otherNotes = otherNotes;
    }

    public String getLikeNum() {
        return likeNum;
    }

    public void setLikeNum(String likeNum) {
        this.likeNum = likeNum;
    }

    public String getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = timeZone;
    }

    public List<CategoryInfo> getCateList() {
        return cateList;
    }

    public void setCateList(List<CategoryInfo> cateList) {
        this.cateList = cateList;
    }

    public void copyExtInfo2OtherNotes(){
        ExtInfo extInfo = getExtInfoObject();
        if (extInfo != null){
            otherNotes.setServiceNotice(extInfo.getServiceNotice());
            otherNotes.setServiceSafeTips(extInfo.getServiceSafeTips());
            otherNotes.setServiceWearTips(extInfo.getServiceWearTips());
            otherNotes.setUnexpectedWeather(extInfo.getUnexpectedWeather());
        }

    }

    public ArrayList<PictureDescription> getPictureDescriptionList() {
        return pictureDescriptionList;
    }

    public void setPictureDescriptionList(ArrayList<PictureDescription> pictureDescriptionList) {
        this.pictureDescriptionList = pictureDescriptionList;
    }

    public void addPictureDescription(PictureDescription pictureDescriptionItem) {
        if (this.pictureDescriptionList == null) {
            this.pictureDescriptionList = new ArrayList<>();
        }
        this.pictureDescriptionList.add(pictureDescriptionItem);
    }

    public TripEditActivity.ContentMode getEditMode() {
        return editMode;
    }

    public void setEditMode(TripEditActivity.ContentMode editMode) {
        this.editMode = editMode;
    }

    public List<Label> getLabelList() {
        return labelList;
    }

    public void setLabelList(List<Label> labelList) {
        this.labelList = labelList;
    }

    public String toCateString() {
        StringBuilder builder = new StringBuilder();
        if (!ArrayUtil.isNullOrEmpty(cateList)) {
            for (int i = 0; i < cateList.size(); i++) {
                builder.append(cateList.get(i).getName());
                if (i != cateList.size() - 1) {
                    builder.append(" / ");
                }
            }
        }
        return builder.toString();
    }

    public static class ExtInfo {

        private String refuseReason;

        private String serviceNotice;

        private String unexpectedWeather;

        private String serviceSafeTips;

        private String serviceWearTips;

        public String getServiceNotice() {
            return serviceNotice;
        }

        public void setServiceNotice(String serviceNotice) {
            this.serviceNotice = serviceNotice;
        }

        public String getUnexpectedWeather() {
            return unexpectedWeather;
        }

        public void setUnexpectedWeather(String unexpectedWeather) {
            this.unexpectedWeather = unexpectedWeather;
        }

        public String getServiceSafeTips() {
            return serviceSafeTips;
        }

        public void setServiceSafeTips(String serviceSafeTips) {
            this.serviceSafeTips = serviceSafeTips;
        }

        public String getServiceWearTips() {
            return serviceWearTips;
        }

        public void setServiceWearTips(String serviceWearTips) {
            this.serviceWearTips = serviceWearTips;
        }

        public String getRefuseReason() {
            return refuseReason;
        }

        public void setRefuseReason(String refuseReason) {
            this.refuseReason = refuseReason;
        }
    }
}
